package com.cdgeekcamp.redas.lib.core.jsonObject;

import com.cdgeekcamp.redas.lib.core.RedasException;
import com.google.gson.Gson;

import java.lang.reflect.Type;

public class JsonObject {
    private Gson gson;

    public JsonObject() {
        this.gson = new Gson();
    }

    public <T> T fromJson(String jsonString, Class<T> classOfT) throws RedasException {
        try {
            return gson.fromJson(jsonString, classOfT);
        } catch (Exception exception) {
            throw new RedasException("JSON字符串转换到 JsonObject 对象错误");
        }
    }

    public<T> String toJson(T t) {
        return gson.toJson(t);
    }
}
